package com.converter.huawei.task;

import cn.hutool.core.util.ObjectUtil;
import com.converter.huawei.utils.HuaweiUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

/**
 * Created by 崔晓阳.
 * Email: 15373889135@189.cn
 * Date: 2022/06/23
 * Time: 15:30
 * Project: huawei
 */
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class HeartTaskJob {

    //3.添加定时任务
    @Scheduled(cron = "*/5 * * * * ?")
    //或直接指定时间间隔，例如：30秒
    //@Scheduled(fixedRate=5000)
    private void configureTasks() {
        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
        for(String key:HuaweiUtils.param.keySet()){
            String ip = key.contains("cookie")?key.replace("cookie","").split("#")[0]:key.replace("csrftoken","").split("#")[0];
            String userName = key.contains("cookie")?key.replace("cookie","").split("#")[1]:key.replace("csrftoken","").split("#")[1];
            System.out.println("ip:====="+ip);
            if(key.contains("cookie")){
                String res = HuaweiUtils.heartBeat(ip,userName);
                System.err.println(ip + "心跳返回: " + res);
            }
        }
    }
}
